//
//  SRTimeSettingView.m
//  SportRing
//
//  Created by mykoma on 14-4-10.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRTimeSettingView.h"
#import <TPKeyboardAvoidingScrollView.h>
#import "LGTimeView.h"

@interface SRTimeSettingView ()
{
    TPKeyboardAvoidingScrollView * _mainScrollView;
    
    UIButton * _upHourBtn;
    UIButton * _downHourBtn;
    UIButton * _upMinuteBtn;
    UIButton * _downMinuteBtn;
    
    LGTimeView * _hourView;
    UIImageView * _colonIV;
    LGTimeView * _minuteView;
}

@end

@implementation SRTimeSettingView

-(NSInteger)hourValue
{
    return _hourView.value;
}

-(NSInteger)minuteValue
{
    return _minuteView.value;
}

-(void)setupViews
{
    _mainScrollView = [[TPKeyboardAvoidingScrollView alloc] init];
    [self addSubview:_mainScrollView];
    
    _upHourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_upHourBtn setImage:[UIImage imageNamed:@"select_up"] forState:UIControlStateNormal];
    [_upHourBtn addTarget:self
                   action:@selector(increaseHour)
         forControlEvents:UIControlEventTouchUpInside];
    [_mainScrollView addSubview:_upHourBtn];
    
    _downHourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_downHourBtn setImage:[UIImage imageNamed:@"select_down"] forState:UIControlStateNormal];
    [_downHourBtn addTarget:self
                     action:@selector(decreaseHour)
           forControlEvents:UIControlEventTouchUpInside];
    [_mainScrollView addSubview:_downHourBtn];
    
    _upMinuteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_upMinuteBtn setImage:[UIImage imageNamed:@"select_up"] forState:UIControlStateNormal];
    [_upMinuteBtn addTarget:self
                     action:@selector(increaseMinute)
           forControlEvents:UIControlEventTouchUpInside];
    [_mainScrollView addSubview:_upMinuteBtn];
    
    _downMinuteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_downMinuteBtn setImage:[UIImage imageNamed:@"select_down"] forState:UIControlStateNormal];
    [_downMinuteBtn addTarget:self
                       action:@selector(decreaseMinute)
             forControlEvents:UIControlEventTouchUpInside];
    [_mainScrollView addSubview:_downMinuteBtn];
    
    _hourView = [LGTimeView timeViewWithStyle:LG_TIME_STYLE_TYPE_HOUR defaultNumber:10];
    [_mainScrollView addSubview:_hourView];
    
    _colonIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"colon"]];
    [_mainScrollView addSubview:_colonIV];
    
    _minuteView = [LGTimeView timeViewWithStyle:LG_TIME_STYLE_TYPE_MINUTE defaultNumber:58];
    [_mainScrollView addSubview:_minuteView];
}

-(void)layoutPortrait
{
    _mainScrollView.frame = self.bounds;
    _upHourBtn.frame = CGRectMake(46, 69, 97, 62);
    _upMinuteBtn.frame = CGRectMake(181, 69, 97, 62);
    _downHourBtn.frame = CGRectMake(46, 212, 97, 62);
    _downMinuteBtn.frame = CGRectMake(181, 212, 97, 62);
    _hourView.frame = CGRectMake(45, 137, 100, 70);
    _colonIV.frame = CGRectMake(157, 150, 8.5, 50);
    _minuteView.frame = CGRectMake(180, 137, 100, 70);
}

#pragma mark - Button Actions

-(void)increaseHour
{
    [_hourView increase];
}

-(void)decreaseHour
{
    [_hourView decrease];
}

-(void)increaseMinute
{
    [_minuteView increase];
}

-(void)decreaseMinute
{
    [_minuteView decrease];
}

@end
